import { Allow, IsNumber, IsOptional, IsString, Matches } from "class-validator";
import { Transform } from "class-transformer";

export class logDto{

  @IsNumber()
  userId: number;

  @IsString()
  username: string;

  @IsString()
  method: string;

  @IsString()
  path: string;

  @IsString()
  ip: string;

  @IsString()
  device: string;

  @IsString()
  os: string;

  @IsString()
  browser: string;

  @IsNumber()
  status: number;

  @IsString()
  errDetail: string;
}

//查询日志的DTO
export class GetLogDto {
  @Allow()
  pageSize: number;

  @Allow()
  pageNo: number;

  //模糊查询字段 - 这个可以查询所有的字段
  @Allow()
  search: string;

  //排序
  @Allow()
  @Matches(RegExp('ASC|DESC'), { message: '排序方式错误' })
  @Transform((params) => String(params.value).toUpperCase())
  @IsOptional()
  sort?: 'ASC' | 'DESC' = 'DESC';


  @IsString({ message: '排序字段必须为字符串' })
  @IsOptional()
  orderBy?: string;
}